﻿Public Class fMascrosMovimi
    Dim daEnMacroMov As lbGlobalcom.dsGlobalAutoMovimiTableAdapters.GLO_ENCAMACROMOVIMITableAdapter
    Dim daDeMacroMov As lbGlobalcom.dsGlobalAutoMovimiTableAdapters.GLO_DETAMACROMOVIMITableAdapter
    Private lElimina As Boolean = False
    Private Sub fMascrosMovimi_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            daEnMacroMov = New lbGlobalcom.dsGlobalAutoMovimiTableAdapters.GLO_ENCAMACROMOVIMITableAdapter
            daDeMacroMov = New lbGlobalcom.dsGlobalAutoMovimiTableAdapters.GLO_DETAMACROMOVIMITableAdapter
            daEnMacroMov.Fill(DsGlobalAutoMovimi.GLO_ENCAMACROMOVIMI)
            daDeMacroMov.Fill(DsGlobalAutoMovimi.GLO_DETAMACROMOVIMI)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    Private Sub SalvarRegistros(ByVal msj As Boolean)
        Try
            Validate()
            GLO_DETAMACROMOVIMIBindingSource.EndEdit()
            GLO_ENCAMACROMOVIMIBindingSource.EndEdit()
            If lElimina Then
                daDeMacroMov.Update(DsGlobalAutoMovimi.GLO_DETAMACROMOVIMI)
                daEnMacroMov.Update(DsGlobalAutoMovimi.GLO_ENCAMACROMOVIMI)
                lElimina = False
            Else
                daEnMacroMov.Update(DsGlobalAutoMovimi.GLO_ENCAMACROMOVIMI)
                daDeMacroMov.Update(DsGlobalAutoMovimi.GLO_DETAMACROMOVIMI)
            End If
            If msj Then _
                MessageBox.Show("Se salvarón registros con exito", "Salvar Registros", MessageBoxButtons.OK)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    Private Sub GLO_ENCAMACROMOVIMIBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GLO_ENCAMACROMOVIMIBindingNavigatorSaveItem.Click
        Try
            SalvarRegistros(True)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        Try
            GLO_ENCAMACROMOVIMIBindingSource.RemoveCurrent()
            lElimina = True
            SalvarRegistros(False)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub GLO_DETAMACROMOVIMIDataGridView_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles GLO_DETAMACROMOVIMIDataGridView.GotFocus
        GLO_ENCAMACROMOVIMIBindingSource.EndEdit()
    End Sub

    Private Sub GLO_DETAMACROMOVIMIDataGridView_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles GLO_DETAMACROMOVIMIDataGridView.KeyDown
        If e.Control Then
            Select Case e.KeyCode
                Case Keys.B
                    Dim fLTDoc As New fListaTipoDocs
                    If fLTDoc.ShowDialog = Windows.Forms.DialogResult.OK Then
                        GLO_DETAMACROMOVIMIDataGridView.BeginEdit(False)
                        GLO_DETAMACROMOVIMIDataGridView.CurrentRow.Cells("IDDOCUMENTO").Value = fLTDoc.idTipoDoc
                        GLO_DETAMACROMOVIMIDataGridView.EndEdit()
                    End If
            End Select
        End If
    End Sub

    Private Sub GLO_DETAMACROMOVIMIDataGridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles GLO_DETAMACROMOVIMIDataGridView.CellContentClick

    End Sub
End Class